<template>
  <div id="threshold">
    <el-row>
      <el-col :span="12">
        <div class="title">设备列表</div>
      </el-col>
      <el-col :span="12">
        <div v-if="userType != 0"
             style="text-align:right">
          <el-button type="primary"
                     @click="sbumitBtn">保存</el-button>
        </div>
      </el-col>
    </el-row>

    <div style="width:90%;margin:0 auto;">
      <el-row :gutter="20"
              v-for="(item,index) in list"
              :key="index"
              style="margin-bottom:15px;">
        <div>
          <el-col :span="6">
            <div style="line-height:40px">{{nameList[item.type].name}}</div>
          </el-col>
          <el-col :span="5">
            <el-row>
              <el-col :span="10">
                <span style="line-height:40px">下限</span>
              </el-col>
              <el-col :span="14">
                <el-input v-model="item.low"></el-input>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="5">
            <el-row>
              <el-col :span="10">
                <span style="line-height:40px">上限</span>
              </el-col>
              <el-col :span="14">
                <el-input v-model="item.high"></el-input>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="8">
            <div style="line-height:40px">{{nameList[item.type].unit}}</div>
          </el-col>
        </div>

      </el-row>
    </div>
  </div>
</template>

<script>
import { thresholdsBatch, thresholdsAll } from '../../api/index'
export default {
  data() {
    return {
      userType: JSON.parse(localStorage.getItem('user')).type,
      nameList: {
        i1: {
          name: '加热电流',
          unit: 'A',
        },
        i2: {
          name: '搅拌电流',
          unit: 'A',
        },
        i3: {
          name: '风扇电流',
          unit: 'A',
        },
        i4: {
          name: '推杆电流',
          unit: 'A',
        },
        ht1: {
          name: '连续加热时间',
          unit: '分钟',
        },
        jt1: {
          name: '连续搅拌时间',
          unit: '分钟',
        },
        ft1: {
          name: '连续风扇时间',
          unit: '分钟',
        },
        tt1: {
          name: '连续推杆时间',
          unit: '分钟',
        },
        kt1: {
          name: '连续探测时间',
          unit: '分钟',
        },
        ht2: {
          name: '连续不加热时间',
          unit: '分钟',
        },
        jt2: {
          name: '连续不搅拌时间',
          unit: '分钟',
        },
        ft2: {
          name: '连续不吹风时间',
          unit: '分钟',
        },
      },
      list: [],
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      thresholdsAll().then((res) => {
        console.log(res)
        this.list = res.data
      })
    },
    sbumitBtn() {
      thresholdsBatch(this.list).then((res) => {
        console.log(res)
        if (res.code == 0) {
          this.$message.success(res.msg)
          this.getData()
        }
      })
    },
  },
}
</script>

<style scoped>
#threshold {
  padding: 40px;
}
.title {
  color: #202224;
  border-left: 3px solid #4a76ff;
  padding-left: 9px;
  margin-bottom: 30px;
}
</style>